<template>
	<view>
		<u-form :model="form" ref="uForm">
			<u-form-item label="用户名"><u-input v-model="form.username" /></u-form-item>
			<u-form-item label="密码"><u-input v-model="form.password" /></u-form-item>
			<view @click="doregist">
				<!-- <u-link :under-line="true" @click="doregist">用户注册</u-link> -->
				<!-- <u-link href="http://www.uviewui.com" :under-line="true">蒹葭苍苍，白露为霜</u-link> -->
				<span style="color: blue;">新用户注册</span>
			</view>
			
			<view class="flex-center">
				<u-button type="primary" text="用户登录" @click="dosubmit"></u-button>
			</view>
			
		</u-form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form : {}
			}
		},
		methods: {
			doregist(){
				console.log("12345678");
			},
			dosubmit(){
				//登录获取openid
				uni.login({
				  provider: 'weixin', //使用微信登录
				  onlyAuthorize:true,
				  success: loginRes=> {
					console.log(loginRes.code);
					uni.request({
						method: 'POST',
					    url: 'http://localhost:33003/auth/shiro/login',
					    data: {
							"username": this.form.username,
							"password": this.form.password
						},
					    success: (res) => {
							if('200' == res.data.errorCode){
								//存储token
								uni.setStorageSync('token',res.data.result.token);
								//存储用户信息
								let userinfo = {
									"name": res.data.result.name,
									"phoneNumber": res.data.result.phoneNumber,
									"pic": res.data.result.pic
								}
								uni.setStorageSync('userinfo',userinfo);
								
								//跳转首页
								uni.switchTab({
									url:"/pages/index/index"
								})
							}
					        
					    }
					});
					
					
				  }
				});

				//注册
				
				//注册成功
				// uni.switchTab({
				// 	url:"/pages/index/index"
				// })
				//can not navigateTo a tabbar page
				// uni.navigateTo({
				// 	url:"/pages/index/index"
				// })
			}
		}
	}
</script>

<style lang="scss">
.flex-center {
	display: flex;
	justify-content: center; /* 水平居中 */
}
</style>
